Skip to content

Route sys_statfs through the /proc intercept#193

Merged
jserv merged 1 commit into
sysprog21:mainfrom
Max042004:fix-statfs-proc-match
Jul 12, 2026
Merged

Route sys_statfs through the /proc intercept#193
jserv merged 1 commit into
sysprog21:mainfrom
Max042004:fix-statfs-proc-match

Conversation

@Max042004

@Max042004 Max042004 commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

/proc entries are synthesized on open with no backing file under
the sysroot (see proc_intercept_open), so a raw statfs() on any
/proc path -- including the literal "/proc" -- fails with ENOENT even
though stat() and open() on the same path succeed. Confirmed by
cross-compiling a guest probe and running it under elfuse:
stat("/proc") succeeded while statfs("/proc") returned ENOENT.

Fix sys_statfs to route /proc paths through proc_intercept_open,
fstatfs the resulting host fd, and close it, mirroring how sys_newfstatat
already resolves /proc via proc_intercept_stat. The prefix check is
boundary-safe (rejects "/procfoo") to avoid reintroducing the naive-match
class of bug the issue warns about.

While reproducing this, found that proc_intercept_open's bare "/proc"
case lacked the trailing-slash variant present on all its children (e.g. "/proc/self/"),
so statfs("/proc/") missed even after the fix above; stat() already handled it
via proc_intercept_stat's separate check. Added the missing variant for consistency.

Add regression coverage to test-proc.c: statfs on "/proc", "/proc/", and a synthetic
file, plus an f_type cross-check against fstatfs on an already-open fd of the same path.


Summary by cubic

Fix ENOENT from statfs on /proc paths by routing them through the /proc intercept so statfs matches stat/open, and avoid scratch-dir allocation for /proc/self/{fd,fdinfo}. Also handle the /proc/ trailing-slash case and extend tests.

  • Bug Fixes
    • sys_statfs: boundary-check /proc paths; try proc_intercept_statfs for /proc/self/{fd,fdinfo} (statfs /tmp to avoid per-open scratch), else use proc_intercept_openfstatfs; fall back to host statfs if not intercepted.
    • proc_intercept_open: accept "/proc/" to match "/proc".
    • Tests: statfs("/proc"), statfs("/proc/"), statfs("/proc/self/cmdline"); confirm f_type matches fstatfs; repeat statfs on /proc/self/fd and /proc/self/fdinfo past the tracking cap.

Written for commit 0795592. Summary will update on new commits.

Review in cubic

cubic-dev-ai[bot]

This comment was marked as resolved.

@Max042004 Max042004 force-pushed the fix-statfs-proc-match branch from c5f0ff3 to aa5f7fd Compare July 11, 2026 16:40
jserv

This comment was marked as resolved.

/proc entries are synthesized on open with
no backing file under the sysroot (see proc_intercept_open), so a raw
statfs() on any /proc path -- including the literal "/proc" -- fails
with ENOENT even though stat() and open() on the same path succeed.
Confirmed by cross-compiling a guest probe and running it under
elfuse: stat("/proc") succeeded while statfs("/proc") returned ENOENT.

Fix sys_statfs to route /proc paths through proc_intercept_open,
fstatfs the resulting host fd, and close it, mirroring how
sys_newfstatat already resolves /proc via proc_intercept_stat. The
prefix check is boundary-safe (rejects "/procfoo") to avoid
reintroducing the naive-match class of bug the issue warns about.

While reproducing this, found that proc_intercept_open's bare "/proc"
case lacked the trailing-slash variant present on all its children
(e.g. "/proc/self/"), so statfs("/proc/") missed even after the fix
above; stat() already handled it via proc_intercept_stat's separate
check. Added the missing variant for consistency.

Review flagged that routing /proc/self/fd and /proc/self/fdinfo
through proc_intercept_open makes statfs() pay for those nodes'
per-open scratch directory -- one placeholder file per live guest fd,
needed only so getdents has something to list -- even though statfs()
never enumerates it. Past PROC_SCRATCH_DIRS_MAX untracked opens, the
leaked dirs also stop getting cleaned up at exit. Add
proc_intercept_statfs, a lightweight resolver that recognizes just
those two nodes and statfs()es /tmp directly (every scratch dir lives
under /tmp, so the filesystem info is identical); sys_statfs tries it
first and only falls back to proc_intercept_open for every other
/proc path.

Add regression coverage to test-proc.c: statfs on "/proc", "/proc/",
and a synthetic file, plus an f_type cross-check against fstatfs on
an already-open fd of the same path; repeated statfs on
/proc/self/fd and /proc/self/fdinfo past the scratch-dir tracking cap.
@Max042004 Max042004 force-pushed the fix-statfs-proc-match branch from aa5f7fd to 0795592 Compare July 12, 2026 13:15
@jserv jserv merged commit 718f908 into sysprog21:main Jul 12, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants